import axios from "axios";

import nprogress from 'nprogress';

const requests = axios.create({
    baseURL: 'http://localhost:8080/api',
    timeout: 5000,
});

requests.interceptors.request.use(
    (config) => {
        nprogress.start();
        console.log(config);
        return config;
    },
    (error) => {
        Promise.reject(error);
    }
);

requests.interceptors.response.use((resp) => {
    nprogress.done();
    // console.log('success');
    // console.log(resp);
    return resp.data;
}, (error) => {
    nprogress.done();
    // console.log('fail');
    alert('请求失败，请查看网络是否连接正常');
    return error;
});

export default requests;